/* (C) Copyright 2008 Bill Buckels */

/*
   TIME2A.c by bill buckels

   reward module for module 2 of "What Time is It"
   June 1991


*/



#include <stdio.h>
#include <fcntl.h>
#include <prodos.h>
#include <sgtty.h>
#include <device.h>
#include <sysfunc.h>

/* musical array created from file thunder.snd */
/* array structure is octave, note, duration */
char thunder[]={
 4,  0,  3, 7,  0,  1, 3, 11,  3, 7,  0,  1, 3, 10,  1, 7,  0,  1,
 3, 11,  1, 7,  0,  1, 3, 10,  1, 7,  0,  1, 3,  9,  1, 7,  0,  1,
 3,  8,  3, 7,  0,  1, 3,  7,  3, 7,  0,  1, 3,  6,  3, 7,  0,  1,
 3,  7,  3, 7,  0,  1, 3,  9,  3, 7,  0,  1, 3,  8,  3, 7,  0,  1,
 3,  7,  1, 7,  0,  1, 3,  8,  1, 7,  0,  1, 3,  7,  1, 7,  0,  1,
 3,  6,  1, 7,  0,  1, 3,  5,  3, 7,  0,  1, 3,  4,  3, 7,  0,  1,
 3,  3,  3, 7,  0,  1, 3,  4,  3, 7,  0,  1, 3,  7,  1, 7,  0,  1,
 7,  0,  1, 7,  0,  1, 3,  2,  1, 7,  0,  1, 3,  2,  1, 7,  0,  1,
 3,  1,  3, 7,  0,  1, 3,  2,  3, 7,  0,  1, 3,  7,  1, 7,  0,  1,
 7,  0,  1, 7,  0,  1, 3,  2,  1, 7,  0,  1, 3,  2,  1, 7,  0,  1,
 3,  1,  3, 7,  0,  1, 3,  2,  3, 7,  0,  1, 2, 11,  1, 7,  0,  1,
 3,  0,  1, 7,  0,  1, 3,  1,  1, 7,  0,  1, 3,  2,  1, 7,  0,  1,
 3,  3,  1, 7,  0,  1, 3,  4,  1, 7,  0,  1, 3,  5,  1, 7,  0,  1,
 3,  6,  1, 7,  0,  1, 3,  7,  1, 7,  0,  1, 3,  8,  1, 7,  0,  1,
 3,  9,  1, 7,  0,  1, 3, 11,  1, 7,  0,  1, 3,  9,  3, 7,  0,  1,
 3,  7,  3, 7,  0,  1, 4,  0,  3, 7,  0,  1, 3, 11,  3, 7,  0,  1,
 3, 10,  1, 7,  0,  1, 3, 11,  1, 7,  0,  1, 3, 10,  1, 7,  0,  1,
 3,  9,  1, 7,  0,  1, 3,  8,  3, 7,  0,  1, 3,  7,  3, 7,  0,  1,
 3,  6,  3, 7,  0,  1, 3,  7,  3, 7,  0,  1, 3,  9,  3, 7,  0,  1,
 3,  8,  3, 7,  0,  1, 3,  7,  1, 7,  0,  1, 3,  8,  1, 7,  0,  1,
 3,  7,  1, 7,  0,  1, 3,  6,  1, 7,  0,  1, 3,  5,  3, 7,  0,  1,
 3,  4,  3, 7,  0,  1, 3,  3,  3, 7,  0,  1, 3,  4,  3, 7,  0,  1,
 3,  2,  3, 7,  0,  1, 3,  2,  1, 7,  0,  1, 3,  2,  1, 7,  0,  1,
 3,  9,  3, 7,  0,  1, 3,  2,  3, 7,  0,  1, 3,  3,  3, 7,  0,  1,
 3,  4,  1, 7,  0,  1, 3,  4,  1, 7,  0,  1, 3, 10,  7, 7,  0,  1,
 3, 11,  1, 7,  0,  1, 4,  2,  1, 7,  0,  1, 4,  1,  1, 7,  0,  1,
 4,  0,  1, 7,  0,  1, 3, 11,  3, 7,  0,  1, 3,  9,  3, 7,  0,  1,
 3,  7,  3, 7,  0,  1, 3,  7,  1, 7,  0,  1, 3,  7,  1, 7,  0,  1,
 3,  7,  1, 7,  0,  1, 3,  5,  1, 7,  0,  1, 3,  4,  1, 7,  0,  1,
 3,  2,  1, 7,  0,  1, 3,  0,  7, 7,  0,  1, 2,  7,  3, 7,  0,  1,
 3,  0,  3, 7,  0,  1, 2, 11,  1, 7,  0,  1, 3,  0,  1, 7,  0,  1,
 3,  1,  1, 7,  0,  1, 3,  2,  1, 7,  0,  1, 3,  3,  1, 7,  0,  1,
 3,  4,  1, 7,  0,  1, 3,  5, 11, 7,  0,  1, 3,  4,  3, 7,  0,  1,
 3,  2, 16, 7,  0,  1, 3,  9, 11, 7,  0,  1, 3,  7,  3, 7,  0,  1,
 3,  5,  1, 7,  0,  1, 3,  7,  1, 7,  0,  1, 3,  5,  1, 7,  0,  1,
 3,  4,  1, 7,  0,  1, 3,  2,  1, 7,  0,  1, 3,  4,  1, 7,  0,  1,
 3,  5,  1, 7,  0,  1, 3,  2,  1, 7,  0,  1, 3,  0, 11, 7,  0,  1,
'\xff','\xff','\xff'};


/* the auxmem (ems) library info */
/* graphics library map for library TIME.RIB */

/* lib info for character array created from fragment HOURMENU.BOT */
#define HOURMENU_SIZE   7680
#define HOURMENU_WIDTH  40
#define HOURMENU_HEIGHT 192
#define HOURMENU_OFFSET 0

/* lib info for character array created from fragment TIME0A.RAG */
#define TIME0A_SIZE   1296
#define TIME0A_WIDTH  16
#define TIME0A_HEIGHT 81
#define TIME0A_OFFSET 7680

/* lib info for character array created from fragment TIME1A.RAG */
#define TIME1A_SIZE   3276
#define TIME1A_WIDTH  26
#define TIME1A_HEIGHT 126
#define TIME1A_OFFSET 8976

/* lib info for character array created from fragment TIME2A.RAG */
#define TIME2A_SIZE   3264
#define TIME2A_WIDTH  24
#define TIME2A_HEIGHT 136
#define TIME2A_OFFSET 12252

/* lib info for character array created from fragment ELBOW.RAG */
#define ELBOW_SIZE   96
#define ELBOW_WIDTH  4
#define ELBOW_HEIGHT 24
#define ELBOW_OFFSET 15516

/* lib info for character array created from fragment ELBOW2.RAG */
#define ELBOW2_SIZE   96
#define ELBOW2_WIDTH  4
#define ELBOW2_HEIGHT 24
#define ELBOW2_OFFSET 15612

/* lib info for character array created from fragment DOWNPIPE.RAG */
#define DOWNPIPE_SIZE   64
#define DOWNPIPE_WIDTH  4
#define DOWNPIPE_HEIGHT 16
#define DOWNPIPE_OFFSET 15708

/* lib info for character array created from fragment DOWN2.RAG */
#define DOWN2_SIZE   64
#define DOWN2_WIDTH  4
#define DOWN2_HEIGHT 16
#define DOWN2_OFFSET 15772

/* lib info for character array created from fragment SPOUT.RAG */
#define SPOUT_SIZE   496
#define SPOUT_WIDTH  16
#define SPOUT_HEIGHT 31
#define SPOUT_OFFSET 15836

/* lib info for character array created from fragment SPOUT2.RAG */
#define SPOUT2_SIZE   496
#define SPOUT2_WIDTH  16
#define SPOUT2_HEIGHT 31
#define SPOUT2_OFFSET 16332

/* lib info for character array created from fragment WAVE.RAG */
#define WAVE_SIZE   1704
#define WAVE_WIDTH  24
#define WAVE_HEIGHT 71
#define WAVE_OFFSET 16828

/* lib info for character array created from fragment WAVENO.RAG */
#define WAVENO_SIZE   1704
#define WAVENO_WIDTH  24
#define WAVENO_HEIGHT 71
#define WAVENO_OFFSET 18532

/* lib info for character array created from fragment BOTGLAS.RAG */
#define BOTGLAS_SIZE   580
#define BOTGLAS_WIDTH  10
#define BOTGLAS_HEIGHT 58
#define BOTGLAS_OFFSET 20816

/* lib info for character array created from fragment TIME1B.RAG */
#define TIME1B_SIZE   968
#define TIME1B_WIDTH  22
#define TIME1B_HEIGHT 44
#define TIME1B_OFFSET 21396

/* lib info for character array created from fragment TIME1C.RAG */
#define TIME1C_SIZE   968
#define TIME1C_WIDTH  22
#define TIME1C_HEIGHT 44
#define TIME1C_OFFSET 22364

/* lib info for character array created from fragment TIME1D.RAG */
#define TIME1D_SIZE   912
#define TIME1D_WIDTH  16
#define TIME1D_HEIGHT 57
#define TIME1D_OFFSET 23332

/* lib info for character array created from fragment TOPGLAS.RAG */
#define TOPGLAS_SIZE   580
#define TOPGLAS_WIDTH  10
#define TOPGLAS_HEIGHT 58
#define TOPGLAS_OFFSET 24244

/* lib info for character array created from fragment WORM0.RAG */
#define WORM0_SIZE   408
#define WORM0_WIDTH  8
#define WORM0_HEIGHT 51
#define WORM0_OFFSET 24824

/* lib info for character array created from fragment WORM1.RAG */
#define WORM1_SIZE   408
#define WORM1_WIDTH  8
#define WORM1_HEIGHT 51
#define WORM1_OFFSET 25232

/* lib info for character array created from fragment WORM2.RAG */
#define WORM2_SIZE   408
#define WORM2_WIDTH  8
#define WORM2_HEIGHT 51
#define WORM2_OFFSET 25640

/* lib info for character array created from fragment LIGHTON.RAG */
#define LIGHTON_SIZE   76
#define LIGHTON_WIDTH  4
#define LIGHTON_HEIGHT 19
#define LIGHTON_OFFSET 26048

/* lib info for character array created from fragment LIGHTOFF.RAG */
#define LIGHTOFF_SIZE   76
#define LIGHTOFF_WIDTH  4
#define LIGHTOFF_HEIGHT 19
#define LIGHTOFF_OFFSET 26124

/* lib info for character array created from fragment TIME2B.RAG */
#define TIME2B_SIZE   638
#define TIME2B_WIDTH  22
#define TIME2B_HEIGHT 29
#define TIME2B_OFFSET 26200

extern int soundflag;

#define PUT 0    /* action verbs for putimage */
#define GET 1    /* expand as required */
#define P_STIX  2
#define P_BLACK 3
#define P_WHITE 4
#define P_AND   5
#define P_XOR   6


#define SNL_SIZE   350
#define SNL_WIDTH  10
#define SNL_HEIGHT 35

extern char *SNLBACK;
extern char *LEFTSNL;
extern char *RIGHTSNL;

/* a pointer to the library buffer in memory */
extern char *SNAIL;



ovmain()
{
       extern hourslimit;
       int i;

       /* take a bite of the apple */
       sound(7,0,20);
       putimage(SNLBACK,SNL_WIDTH,SNL_HEIGHT,
                22,156,PUT);
       putimage(RIGHTSNL,SNL_WIDTH,SNL_HEIGHT,
                10,156,P_AND);
       sound(7,0,20);

       if(hourslimit>12)
       emsputimage(WORM2_OFFSET,
                   WORM2_WIDTH,WORM1_HEIGHT,
                   4,139,PUT);
       else
       emsputimage(WORM1_OFFSET,
                   WORM1_WIDTH,WORM1_HEIGHT,
                   4,139,PUT);



       hourslimit=12;
       putimage(RIGHTSNL,SNL_WIDTH,SNL_HEIGHT,
                12,156,PUT);
       sound(7,0,20);
       putimage(LEFTSNL,SNL_WIDTH,SNL_HEIGHT,
                12,156,PUT);

       if(soundflag)play(thunder);

       putimage(LEFTSNL,SNL_WIDTH,SNL_HEIGHT,
                12,156,P_BLACK);
       putimage(RIGHTSNL,SNL_WIDTH,SNL_HEIGHT,
                22,156,P_AND);

return 0;
}
